/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.brokerage;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.services.front.brokerage.BrokerageService;
import shop.services.front.brokerage.bean.Brokerage;
import shop.services.manage.system.bean.User;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.util.List;

/**   
 * @类名称：BrokerageController
 * @创建人：Wzl
 * @创建时间：2017-10-24 上午10:00:52      
 * @版本号：1.0
 * @描述：商品返利
 */
@Controller
@RequestMapping("/front/brokerage/")
public class BrokerageController extends FrontBaseController<Brokerage> {
    @Resource
    private BrokerageService brokerageService;
    @Override
    public Services<Brokerage> getService() {
        return brokerageService;
    }


    /**
     * 查询用户总返利
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectBrokerageAmount")
    @ResponseBody
    public JSONResult selectBrokerageAmount(HttpSession session,Brokerage brokerage) throws Exception {
        User user = (User) session.getAttribute("userInfo");
        brokerage.setAffID(user.getId());
        List<Brokerage> rsList = brokerageService.selectList(brokerage);
        BigDecimal brokerageAmount =new BigDecimal(0.00);
        for(Brokerage brokerageInfo : rsList){
            brokerageAmount=brokerageAmount.add(brokerageInfo.getMoney());
        }
        jsonResult = new JSONResult();
        jsonResult.setData(brokerageAmount);
        return jsonResult;
    }
}
